package org.apache.solr.ocean.search;

import java.util.ArrayList;

import org.apache.solr.ocean.cache.BooleanDocSetCacheKey;
import org.apache.solr.ocean.cache.DistanceDocSetCacheKey;
import org.apache.solr.ocean.cache.DocSetCacheKey;

public class Filters extends ArrayList<DocSetCacheKey> {
  
  public Filters(DocSetCacheKey... array) {
    for (DocSetCacheKey key : array) {
      add(key);
    }
  }
  
	public DocSetCacheKey getCacheKey() {
		if (size() == 1) {
			return get(0);
		} else if (size() > 1) {
			return new BooleanDocSetCacheKey(null, null, this);
		} else {
			return null;
		}
	}
  
	public Distance getDistance() {
		for (DocSetCacheKey cacheKey : this) {
			if (cacheKey instanceof DistanceDocSetCacheKey) {
				DistanceDocSetCacheKey distanceDocSetCacheKey = (DistanceDocSetCacheKey)cacheKey;
				return distanceDocSetCacheKey.getDistance();
			}
		}
		return null;
	}
	
	public boolean hasDistance() {
		for (DocSetCacheKey cacheKey : this) {
			if (cacheKey instanceof DistanceDocSetCacheKey) {
				return true;
			}
		}
		return false;
	}
}
